package com.jiepos.mpos.biz.transaction.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jiepos.mpos.biz.channel.service.InfChannelService;
import com.jiepos.mpos.biz.transaction.service.LogChannelStlService;
import com.jiepos.mpos.common.entity.App_Custom_InfEntity;
import com.jiepos.mpos.common.entity.App_Log_ChannelStlEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * @ClassName: LogChannelStlController
 * @Description: 渠道清算流水
 * @author 孙永
 * @date 2018年1月8日 下午3:09:54
 */
@Controller
@RequestMapping("/logChannelStl")
public class LogChannelStlController extends BaseController{
	
	/** 导出excel文件名：渠道结算流水*/
	private static final String EXCEL_FILE_NAME = "渠道结算流水.xls";
	
	@Autowired
	private LogChannelStlService logChannelStlService;
	@Autowired
	private InfChannelService infChannelService;

	@RequestMapping("/list.do")
	public ModelAndView list(HttpServletRequest request, HttpServletResponse response){
		ModelAndView modelAndView = new ModelAndView("/module/transaction/logchannelstl/logchannelstl_list");
		modelAndView.addObject("channels", infChannelService.getChannelByTp(null));
		return super.getDetail(request, response, modelAndView);
	}
	
	@RequestMapping("/jsonList.do")
	@ResponseBody
	public Map<String, Object> getJsonList(Pagination pagination, App_Log_ChannelStlEntity condition, App_Custom_InfEntity customer){
		return logChannelStlService.getChannelStlPageList(pagination, condition, customer);
	}
	
	@RequestMapping("/export.do")
	@ResponseBody
	public void export(HttpServletRequest request, HttpServletResponse response, App_Log_ChannelStlEntity condition, App_Custom_InfEntity customer){
		super.clearCookie(request, response);
		String result = logChannelStlService.createExcel(EXCEL_FILE_NAME, condition, customer);
		if (StringUtils.isBlank(result)) {
			super.setFileParam(request, response, EXCEL_FILE_NAME);
		} else {
			super.setErrorFileParam(request, response, result);
		}
	}
	
}
